package data;

import cpr.Rule;
import cpr.Utils;
import cpr.context.PrintContext;
import cpr.data.HLVector;
import cpr.helper.ScoreHelper;

public class ClusterDescriptor implements IClusterDescriptor {
	public Rule rule;

	public HLVector vector;

	public int size;

	public ClusterDescriptor(Rule aRule, HLVector aVector, int aSize) {
		this.rule = aRule;
		this.vector = aVector;
		this.size = aSize;
	}

	public Rule getRule() {
		return rule;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public HLVector getVector() {
		return vector;
	}

	public void setRule(Rule aRule) {
		this.rule = aRule;
	}
    
    
    public static boolean comparable(IClusterDescriptor c1, IClusterDescriptor c2) {
        if (c1.getVector().equals(c2.getVector())) return true;
        HLVector minVector = c1.getVector();
        if (c1.getVector().compareTo(c2.getVector())>0) {
            minVector = c2.getVector();
        }
        int c1s = Utils.printRuleAccordingToVectorDigital(c1.getRule(), minVector);
        int c2s = Utils.printRuleAccordingToVectorDigital(c2.getRule(), minVector);
        if (c1s==c2s) return true;
        return false;
    }

    public static int compare(IClusterDescriptor c1, IClusterDescriptor c2) {
        if (!comparable(c1,c2)) throw new RuntimeException("trying to compare not comparable!");
        return c1.getVector().compareTo(c2.getVector());
    }

    @Override
    public String toString() {
        //ScoreHelper helper = new ScoreHelper();
        
        String scopeScoreString = ScoreHelper.printHLVectorAsArray(getVector(),"-");
        String scopeRuleString = PrintContext.createRuleDigitalDigest(getRule(), getVector(), "-");
        
        return "Cluster score="+scopeScoreString+" rule="+scopeRuleString+" size="+getSize();
    }
    
    
        

}
